[JBoss Seam] - Re: different behaviour when clicking on a button or using e
by spyman74
Maybe this helps
| /**
| * This JSF component marks the enclosing action component (e.g. h:commandButton) as default, i.e.
| * if the user presses Enter key the enclosing component's action will be performed, e.g.:
| * <code>
| * <h:commandButton action="#{myBean.myAction}">
| * <myprefix:defaultAction//>
| * </h:commandButton>
| * <code>
| * Only one defaultAction per scope is allowed. You can specify the scope by setting
| * the scope attribute. If you set scope="document" (default) then only one component can be marked as
| * defaultAction in the entire HTML document. If you set scope="form" you can have one defaultAction per
| * HTML form.
| *
| */
| public class UIDefaultAction extends UIOutput {
|
| public static final String SCOPE_DOCUMENT = "document";
|
| public static final String SCOPE_FORM = "form";
|
| private String scope = SCOPE_DOCUMENT;
|
| public void encodeBegin(FacesContext context) throws IOException {
| return;
| }
|
| public void decode(FacesContext context) {
| return;
| }
|
| public void encodeEnd(FacesContext context) throws IOException {
| ResponseWriter writer = context.getResponseWriter();
| UIComponent actionComponent = super.getParent();
| String acId = actionComponent.getClientId(context);
| UIForm form = getForm(actionComponent);
| if (form != null) {
|
| String formId = form.getClientId(context);
|
| writer.startElement("script", null);
|
| StringBuilder javascript = new StringBuilder();
|
| javascript.append("function processKeyPress(keyCode) {");
| javascript.append(" if (keyCode == 13) {");
| javascript.append(" document.getElementById('" + acId + "').click();");
| javascript.append(" }");
| javascript.append("}");
|
| javascript.append("function clickEnter(event) {");
| javascript.append(" processKeyPress(event.which);");
| javascript.append("}");
|
| javascript.append("function clickEnterIE() {");
| javascript.append(" processKeyPress(event.keyCode);");
| javascript.append("}");
|
| javascript.append("if (document.all) {");
| javascript.append(" " + getKeyPressEventSource(formId) + " = clickEnterIE;");
| javascript.append("} else {");
| javascript.append(" " + getKeyPressEventSource(formId) + " = clickEnter;");
| javascript.append("}");
|
| writer.write(javascript.toString());
|
| writer.endElement("script");
| }
| }
|
| public String getScope() {
| return scope;
| }
|
| public void setScope(String scope) {
| this.scope = scope;
| }
|
| @Override
| public void restoreState(FacesContext context, Object state) {
| Object[] values = (Object[]) state;
| super.restoreState(context, values[0]);
| this.scope = (String) values[1];
| }
|
| /**
| * @see javax.faces.component.UIComponentBase#saveState(javax.faces.context.FacesContext)
| */
| @Override
| public Object saveState(FacesContext context) {
| Object[] values = new Object[2];
| values[0] = super.saveState(context);
| values[1] = this.scope;
| return values;
|
| }
|
| private String getKeyPressEventSource(String formId) {
| if (SCOPE_FORM.equals(getScope())) {
| return "document.forms['" + formId + "'].onkeypress";
| } else {
| return "document.onkeypress";
| }
| }
|
| private UIForm getForm(UIComponent component) {
| while (component != null) {
| if (component instanceof UIForm) {
| break;
| }
| component = component.getParent();
| }
| return (UIForm) component;
| }
|
| }
|
Works for me in myfaces
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4082004#4082004
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4082004
18 years, 7 months
[JBoss Seam] - Re: How to specify a custom CallbackHandler for JAAS
by lorenz.fischer
Thank you shane!
That's exactly what i found out after doing some more digging in the sourcecode ;) for those being interested in the code that extends the identity:
| package somepackage.security;
|
| import javax.security.auth.callback.CallbackHandler;
|
| import org.jboss.seam.InterceptionType;
| import org.jboss.seam.ScopeType;
| import org.jboss.seam.annotations.Intercept;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Scope;
| import org.jboss.seam.annotations.Startup;
| import org.jboss.seam.log.Log;
| import org.jboss.seam.security.Identity;
|
| /**
| * This class allows us to specify our own CallbackHandler for the JAAS login.
| */
| @Name(value = "org.jboss.seam.security.identity")
| @Scope(ScopeType.SESSION)
| @Intercept(InterceptionType.NEVER)
| @Startup
| public class ConsoleIdentity extends Identity {
|
| @Logger
| private Log log;
|
| /**
| * Supply our own Callbackhandler for the login process
| * @return an instance of ConsoleCallbackHandler
| */
| @Override
| public CallbackHandler getDefaultCallbackHandler() {
| return new ConsoleCallbackHandler(this, log);
| }
|
| }
|
If I got it right its the line
@Name(value = "org.jboss.seam.security.identity")
that does the trick, since this overrides the standard Identity object of Seam?
I used a constructor that lets me pass an identity and a logger, since I couldn't get them over injection in the handler itself.. maybe I'm doing something wrong, but It seems to work like that.
Thank you again.
Cheers
Lorenz
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4081980#4081980
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4081980
18 years, 7 months