001: /*
002: * $Id: BaseComponent.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package org.apache.struts.faces.component;
023:
024: import javax.faces.component.UIOutput;
025: import javax.faces.context.FacesContext;
026: import javax.faces.el.ValueBinding;
027:
028: /**
029: * <p>Custom component that replaces the Struts
030: * <code><html:base></code> tag.</p>
031: */
032:
033: public class BaseComponent extends UIOutput {
034:
035: // ------------------------------------------------------------ Constructors
036:
037: /**
038: * <p>Create a new {@link BaseComponent} with default properties.</p>
039: */
040: public BaseComponent() {
041:
042: super ();
043: setRendererType("org.apache.struts.faces.Base");
044:
045: }
046:
047: // ------------------------------------------------------ Instance Variables
048:
049: /**
050: * <p>Target frame.</p>
051: */
052: private String target = null;
053:
054: // ---------------------------------------------------- Component Properties
055:
056: /**
057: * <p>Return the component family to which this component belongs.</p>
058: */
059: public String getFamily() {
060:
061: return "org.apache.struts.faces.Base";
062:
063: }
064:
065: /**
066: * <p>Return the target frame.</p>
067: */
068: public String getTarget() {
069:
070: ValueBinding vb = getValueBinding("target");
071: if (vb != null) {
072: return (String) vb.getValue(getFacesContext());
073: } else {
074: return target;
075: }
076:
077: }
078:
079: /**
080: * <p>Set the target frame.</p>
081: *
082: * @param target The new target frame
083: */
084: public void setTarget(String target) {
085:
086: this .target = target;
087:
088: }
089:
090: // ---------------------------------------------------- StateManager Methods
091:
092: /**
093: * <p>Restore the state of this component.</p>
094: *
095: * @param context <code>FacesContext</code> for the current request
096: * @param state State object from which to restore our state
097: */
098: public void restoreState(FacesContext context, Object state) {
099:
100: Object values[] = (Object[]) state;
101: super .restoreState(context, values[0]);
102: target = (String) values[1];
103:
104: }
105:
106: /**
107: * <p>Save the state of this component.</p>
108: *
109: * @param context <code>FacesContext</code> for the current request
110: */
111: public Object saveState(FacesContext context) {
112:
113: Object values[] = new Object[2];
114: values[0] = super .saveState(context);
115: values[1] = target;
116: return values;
117:
118: }
119:
120: }
|