[Ajax4JSF] 请教学习JSF中的一点疑问
风之狐
2008-05-13
tomahawk的例子的皮肤实在是太难看了,还得自己开发,要是有一套比较好看的css也好啊
|
|
terryzhou
2008-05-14
css是重要,但性能效率还是第一位的。。。
华丽的等待 还是 普实的效率。。 我想商用来说。。后者更实在也跟容易接受。。。 再说CSS改起来总比改组件的code要简单 |
|
kencool
2008-05-14
terryzhou 写道 <managed-bean>
<managed-bean-name></managed-bean-name> <managed-bean-class></managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <managed-property> <property-name>id</property-name> <value>#{param.id}</value> </managed-property> </managed-bean> 这个方式就可以将javascript和backingBean结合起来了:) |
|
风之狐
2008-05-14
terryzhou 写道 css是重要,但性能效率还是第一位的。。。
华丽的等待 还是 普实的效率。。 我想商用来说。。后者更实在也跟容易接受。。。 再说CSS改起来总比改组件的code要简单 有道理,谢谢你的解答 |
|
kimmking
2008-05-14
关于带参数的方法的调用
1、 使用param传参数 2、 修改MethodBindingImpl |
|
kimmking
2008-05-14
可以使用action="bean.method(123)"这样绑定。
/** * 解析方法绑定的类 * * @author qinjinwei * $date 2007-10-10 上午11:35:41 */ public class JafMethodBinding extends MethodBindingImpl { static final Log log = LogFactory.getLog(MethodBindingImpl.class); //~ Instance fields ------------------------------------------------------- Class[] _argClasses = new Class[]{String.class}; Object[] _args; //~ Constructors ---------------------------------------------------------- public JafMethodBinding(Application application, String reference) { super(application,reference.substring(0, reference.indexOf("(")) + "}",null); int pos1 = reference.indexOf("("); int pos2 = reference.indexOf(")"); //String exp = reference.substring(0, pos1); String arg = reference.substring(pos1 + 1, pos2); _args = new Object[]{arg}; //_argClasses = new Class[]{String.class}; } public Object invoke(FacesContext facesContext, Object[] args) throws EvaluationException, MethodNotFoundException { if (facesContext == null) { throw new NullPointerException("facesContext"); } try { Object[] baseAndProperty = resolveToBaseAndProperty(facesContext); Object base = baseAndProperty[0]; Object property = baseAndProperty[1]; Method m = base.getClass().getMethod(property.toString(), _argClasses ); // Check if the concrete class of this method is accessible and if not // search for a public interface that declares this method m = MethodUtils.getAccessibleMethod(m); if (m == null) { throw new MethodNotFoundException( getExpressionString() + " (not accessible!)"); } return m.invoke(base, _args); } catch (ReferenceSyntaxException e) { throw e; } catch (IndexOutOfBoundsException e) { // ArrayIndexOutOfBoundsException also here throw new PropertyNotFoundException("Expression: " + getExpressionString(), e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause != null) { if (cause instanceof ValidatorException || cause instanceof AbortProcessingException) { throw new EvaluationException(cause); } else { throw new EvaluationException("Exception while invoking expression " + getExpressionString(), cause); } } else { throw new EvaluationException("Exception while invoking expression " + getExpressionString(), e); } } catch (Exception e) { throw new EvaluationException("Exception while invoking expression " + getExpressionString(), e); } } } |
|
风之狐
2008-05-14
kimmking 写道 关于带参数的方法的调用
1、 使用param传参数 2、 修改MethodBindingImpl 请问kimmking,你这个方法怎么用啊,扩展的类怎么配置啊。是全局的还是可以有针对性的 |
|
kimmking
2008-05-15
第三点,输出xml也是可以的。获取response,
reset,修改响应类型,然后输出xml,接着facesContext.responseComplete终止流程。可以在listener或是action中实现。 参考下输出javascript的例子(from clientvalidator) /* * Copyright 2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.sf.jsfcomp.clientvalidators; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.URL; import java.net.URLConnection; import java.util.Map; import javax.faces.context.FacesContext; import javax.faces.event.PhaseEvent; import javax.faces.event.PhaseId; import javax.faces.event.PhaseListener; import javax.servlet.http.HttpServletResponse; import net.sf.jsfcomp.clientvalidators.utils.ClientValidatorUtils; import net.sf.jsfcomp.clientvalidators.utils.ClientValidatorsConstants; /** * @author Cagatay Civici Phaselistener to load resource from jar and handle * ajax requests */ public class ValidatorResourceLoader implements PhaseListener { public void afterPhase(PhaseEvent event) { String rootId = event.getFacesContext().getViewRoot().getViewId(); if (rootId.indexOf(ClientValidatorsConstants.VALIDATOR_RESOURCE_VIEW_ID) != -1) { serveResource(event); } } private void serveResource(PhaseEvent event) { FacesContext facesContext = event.getFacesContext(); Map requestMap = facesContext.getExternalContext().getRequestParameterMap(); String resourceName = ClientValidatorUtils.getResourceName(requestMap); String resourceType = ClientValidatorUtils.getResourceType(requestMap); String contentType = ClientValidatorUtils.getContentType(resourceType); HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); try { URL url = ValidatorResourceLoader.class.getResource("/META-INF/" + resourceName + "." + resourceType); URLConnection connection = url.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); response.setContentType(contentType); response.setStatus(200); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(response.getOutputStream(), response.getCharacterEncoding()); //Send the resource line by line String line = reader.readLine(); while(line != null) { outputStreamWriter.write(line+"\n"); line = reader.readLine(); } outputStreamWriter.flush(); outputStreamWriter.close(); facesContext.responseComplete(); //Stop the jsf lifecycle } catch (Exception exception) { exception.printStackTrace(); } } public void beforePhase(PhaseEvent arg0) { //Do nothing here } public PhaseId getPhaseId() { return PhaseId.RESTORE_VIEW; } } |