001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.faces.components;
034:
035: import com.flexive.faces.FxJsfComponentUtils;
036: import com.flexive.faces.FxJsfUtils;
037: import com.flexive.faces.components.input.FxValueInput;
038: import com.flexive.shared.ContentLinkFormatter;
039: import com.flexive.shared.FxSharedUtils;
040: import com.flexive.shared.value.FxValue;
041:
042: import javax.faces.component.UIOutput;
043: import javax.faces.context.FacesContext;
044: import java.io.IOException;
045:
046: /**
047: * <p>Renders a single result value returned from the flexive SQL search.
048: * At some point in the future, this will also include support for
049: * inline-editing of results.</p>
050: * <p>The value to be rendered is passed in the "value" attribute.</p>
051: *
052: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
053: * @version $Rev: 1 $
054: */
055: public class ResultValue extends UIOutput {
056: public static final String COMPONENT_TYPE = "flexive.ResultValue";
057:
058: private String contentLinkFormat = null;
059: private String itemLinkFormat = null;
060: private ContentLinkFormatter linkFormatter = null;
061:
062: public ResultValue() {
063: setRendererType(null);
064: }
065:
066: public String getContentLinkFormat() {
067: if (contentLinkFormat == null) {
068: contentLinkFormat = FxJsfComponentUtils.getStringValue(
069: this , "contentLinkFormat");
070: }
071: return contentLinkFormat;
072: }
073:
074: public void setContentLinkFormat(String contentLinkFormat) {
075: this .contentLinkFormat = contentLinkFormat;
076: }
077:
078: public String getItemLinkFormat() {
079: if (itemLinkFormat == null) {
080: itemLinkFormat = FxJsfComponentUtils.getStringValue(this ,
081: "itemLinkFormat");
082: }
083: return itemLinkFormat;
084: }
085:
086: public void setItemLinkFormat(String itemLinkFormat) {
087: this .itemLinkFormat = itemLinkFormat;
088: }
089:
090: public ContentLinkFormatter getLinkFormatter() {
091: if (linkFormatter == null) {
092: linkFormatter = (ContentLinkFormatter) FxJsfComponentUtils
093: .getValue(this , "linkFormatter");
094: }
095: if (linkFormatter == null) {
096: linkFormatter = ContentLinkFormatter.getInstance();
097: }
098: return linkFormatter;
099: }
100:
101: public void setLinkFormatter(ContentLinkFormatter linkFormatter) {
102: this .linkFormatter = linkFormatter;
103: }
104:
105: /**
106: * {@inheritDoc}
107: */
108: @Override
109: public void encodeBegin(FacesContext context) throws IOException {
110: final Object value = getValue();
111: if (value instanceof FxValue) {
112: // use FxValueInput component to support inline-editing
113: final FxValueInput input;
114: if (getChildren().size() == 1
115: && getChildren().get(0) instanceof FxValueInput) {
116: // reuse components in a data table
117: input = (FxValueInput) getChildren().get(0);
118: } else {
119: input = (FxValueInput) FxJsfUtils.addChildComponent(
120: this , FxValueInput.COMPONENT_TYPE);
121: }
122: input.setValue(value);
123: input.setReadOnly(true);
124: } else {
125: FxSharedUtils.writeResultValue(context.getResponseWriter(),
126: value, getLinkFormatter(), getContentLinkFormat(),
127: getItemLinkFormat());
128: }
129:
130: }
131: }
|