我对 Apache ISIS 很陌生,我正在尝试通过扩展来添加自定义检票口组件ScalarPanelAbstract
。
我有一个接受pageable
参数的方法。这pageable
是一个由Page number和Page size组成的界面。
//region > findAllWithPage (action)
@Action(semantics = SemanticsOf.SAFE)
public PagedList<Employee> findAllWithPage(
@Parameter(optionality = Optionality.OPTIONAL)
final Pageable pageable) {
return employeeRepository.findByOwner(userTenancyService.owner(), pageable);
}
//endregion
这是使用 action 时的样子findAllWithPage
。它只有一个参数,即可分页。
现在,我想做的是让它接受两个参数,Page number
并且Page size
.
我的问题是,我无法获得两个文本字段的值。这是我得到的错误。
org.apache.wicket.WicketRuntimeException: Method onRequest of interface org.apache.wicket.behavior.IBehaviorListener targeted at org.apache.wicket.ajax.markup.html.form.AjaxButton$1@c6dc7e3 on component [AjaxButton [Component id = okButton]] threw an exception
at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:268)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:241)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:250)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:236)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:890)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
at org.apache.wicket.protocol.http.WicketServlet.doPost(WicketServlet.java:159)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:821)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1685)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1668)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1158)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1090)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
at org.eclipse.jetty.server.Server.handle(Server.java:517)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:261)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:258)
... 44 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.isis.core.metamodel.facets.actions.action.invocation.ActionInvocationFacetForDomainEventAbstract.invokeMethodElseFromCache(ActionInvocationFacetForDomainEventAbstract.java:408)
at org.apache.isis.core.metamodel.facets.actions.action.invocation.ActionInvocationFacetForDomainEventAbstract$2.execute(ActionInvocationFacetForDomainEventAbstract.java:262)
at org.apache.isis.core.metamodel.facets.actions.action.invocation.ActionInvocationFacetForDomainEventAbstract$2.execute(ActionInvocationFacetForDomainEventAbstract.java:223)
at org.apache.isis.applib.services.iactn.Interaction.executeInternal(Interaction.java:173)
at org.apache.isis.applib.services.iactn.Interaction.execute(Interaction.java:143)
at org.apache.isis.core.metamodel.facets.actions.action.invocation.ActionInvocationFacetForDomainEventAbstract.doInvoke(ActionInvocationFacetForDomainEventAbstract.java:311)
at org.apache.isis.core.metamodel.facets.actions.action.invocation.ActionInvocationFacetForDomainEventAbstract$1.execute(ActionInvocationFacetForDomainEventAbstract.java:165)
at org.apache.isis.core.runtime.system.transaction.IsisTransactionManager.executeWithinTransaction(IsisTransactionManager.java:143)
at org.apache.isis.core.runtime.system.transaction.IsisTransactionManager.executeWithinTransaction(IsisTransactionManager.java:133)
at org.apache.isis.core.runtime.services.persistsession.PersistenceSessionServiceInternalDefault.executeWithinTransaction(PersistenceSessionServiceInternalDefault.java:179)
at org.apache.isis.core.metamodel.facets.actions.action.invocation.ActionInvocationFacetForDomainEventAbstract.invoke(ActionInvocationFacetForDomainEventAbstract.java:161)
at org.apache.isis.core.metamodel.specloader.specimpl.ObjectActionDefault.executeInternal(ObjectActionDefault.java:398)
at org.apache.isis.core.metamodel.specloader.specimpl.ObjectActionDefault.execute(ObjectActionDefault.java:387)
at org.apache.isis.core.metamodel.specloader.specimpl.ObjectActionDefault.executeWithRuleChecking(ObjectActionDefault.java:368)
at org.apache.isis.viewer.wicket.model.models.ActionModel.executeAction(ActionModel.java:483)
at org.apache.isis.viewer.wicket.model.models.ActionModel.load(ActionModel.java:462)
at org.apache.isis.viewer.wicket.model.models.ActionModel.load(ActionModel.java:80)
at org.apache.wicket.model.LoadableDetachableModel.getObject(LoadableDetachableModel.java:124)
at org.apache.isis.viewer.wicket.model.models.ActionModel.executeHandlingApplicationExceptions(ActionModel.java:568)
at org.apache.isis.viewer.wicket.ui.components.actions.ActionPanel.executeActionOnTargetAndProcessResults(ActionPanel.java:255)
at org.apache.isis.viewer.wicket.ui.components.actions.ActionPanel.executeAndProcessResults(ActionPanel.java:204)
at org.apache.isis.viewer.wicket.ui.components.actions.ActionParametersFormPanel$ActionParameterForm$1.onSubmit(ActionParametersFormPanel.java:148)
at org.apache.wicket.ajax.markup.html.form.AjaxButton$1.onSubmit(AjaxButton.java:108)
at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior$AjaxFormSubmitter.onSubmit(AjaxFormSubmitBehavior.java:215)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1305)
at org.apache.wicket.markup.html.form.Form.process(Form.java:966)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:788)
at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior.onEvent(AjaxFormSubmitBehavior.java:171)
at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:146)
at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:641)
... 49 more
HMTL:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
<div class="PageablePanel scalarNameAndValueComponentType">
<div class="form-group" wicket:id="scalarIfRegular">
<label wicket:id="scalarName" class="scalarName control-label mandatory">[Label text]</label>
<span class="scalarValueWrapper">
<span class="uploadFile help-block">
<input type="text" class="form-control input-sm" name="scalarValue" wicket:id="scalarValue" />
</span>
</span>
<label wicket:id="scalarName1" class="scalarName control-label mandatory">[Label text]</label>
<span class="scalarValueWrapper">
<span class="uploadFile help-block">
<input type="text" class="form-control input-sm" name="scalarValue1" wicket:id="scalarValue1" />
</span>
<a wicket:id="scalarIfRegularClear" class="btn btn-primary btn-sm"><span class="clearTitle">Clear</span></a>
<span wicket:id="feedback" class="help-block"></span>
<span wicket:id="associatedActionLinksBelow"></span>
</span>
<span wicket:id="associatedActionLinksRight"></span>
</div>
<span wicket:id="scalarIfCompact"> </span>
</div>
</wicket:panel>
</body>
</html>
在PageablePanelAbstract.java
which extendsScalarPanelAbstract
上,有三种方法被覆盖:
addComponentForRegular();
addComponentForCompact();
addFormComponentBehavior();
PageablePanelAbstract.java
public abstract class PageablePanelAbstract<T extends NamedWithMimeType & Serializable> extends ScalarPanelAbstract {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
private static final Logger LOG = LoggerFactory.getLogger(PageablePanelAbstract.class);
private static final String ID_SCALAR_IF_REGULAR = "scalarIfRegular";
private static final String ID_SCALAR_IF_REGULAR_CLEAR = "scalarIfRegularClear";
private static final String ID_SCALAR_NAME = "scalarName";
private static final String ID_SCALAR_VALUE = "scalarValue";
private static final String ID_SCALAR_IF_COMPACT = "scalarIfCompact";
private static final String PAGE_SIZE = "Page Size";
private static final String PAGE_NUMBER = "Page Number";
private TextField<T> textField;
private TextField<T> textField2;
protected WebMarkupContainer scalarTypeContainer;
public PageablePanelAbstract(String id, ScalarModel scalarModel) {
super(id, scalarModel);
}
@Override
protected void onInitialize() {
super.onInitialize();
scalarTypeContainer = new WebMarkupContainer(ID_SCALAR_IF_REGULAR);
scalarTypeContainer.add(new CssClassAppender(getScalarPanelType()));
addOrReplace(scalarTypeContainer);
}
@Override
protected FormGroup addComponentForRegular() {
textField = createTextField(ID_SCALAR_VALUE);
textField.setLabel(Model.of(getModel().getName()));
textField.setRequired(getModel().isRequired());
textField2 = createTextField("scalarValue1");
textField2.setLabel(Model.of(getModel().getName()));
textField2.setRequired(getModel().isRequired());
final FormGroup labelIfRegularTextField = new FormGroup(ID_SCALAR_IF_REGULAR, textField);
labelIfRegularTextField.add(textField);
labelIfRegularTextField.add(textField2);
final Label scalarNameTextField = new Label(ID_SCALAR_NAME, PAGE_NUMBER);
labelIfRegularTextField.add(scalarNameTextField);
final Label scalarNameTextField1 = new Label("scalarName1", PAGE_SIZE);
labelIfRegularTextField.add(scalarNameTextField1);
// find the links...
final List<LinkAndLabel> entityActions = EntityActionUtil.getEntityActionLinksForAssociation(this.scalarModel, getDeploymentCategory());
addPositioningCssTo(labelIfRegularTextField, entityActions);
addOrReplace(labelIfRegularTextField);
addFeedbackOnlyTo(labelIfRegularTextField, textField);
addEditPropertyTo(labelIfRegularTextField);
// ... add entity links to panel (below and to right)
addEntityActionLinksBelowAndRight(labelIfRegularTextField, entityActions);
return labelIfRegularTextField;
}
@Override
protected Component addComponentForCompact() {
final MarkupContainer scalarIfCompact = new WebMarkupContainer(ID_SCALAR_IF_COMPACT);
addOrReplace(scalarIfCompact);
return scalarIfCompact;
}
@Override
protected void addFormComponentBehavior(Behavior behavior) {
textField.add(behavior);
}
protected void onBeforeRenderWhenViewMode() {
updateRegularFormComponents(InputFieldVisibility.NOT_VISIBLE);
}
protected void onBeforeRenderWhenDisabled(final String disableReason) {
updateRegularFormComponents(InputFieldVisibility.NOT_VISIBLE);
}
protected void onBeforeRenderWhenEnabled() {
updateRegularFormComponents(InputFieldVisibility.VISIBLE);
}
@SuppressWarnings("unchecked")
private T getText(final ScalarModel model) {
ObjectAdapter adapter = model.getObject();
return adapter != null ? (T) adapter.getObject() : null;
}
private void updateRegularFormComponents(final InputFieldVisibility visibility) {
MarkupContainer formComponent = (MarkupContainer) getComponentForRegular();
formComponent.get(ID_SCALAR_VALUE).setVisible(visibility == InputFieldVisibility.VISIBLE);
updateClearLink(visibility);
}
private void updateClearLink(InputFieldVisibility visibility) {
final MarkupContainer formComponent = (MarkupContainer) getComponentForRegular();
formComponent.setOutputMarkupId(true); // enable ajax link
final AjaxLink<Void> ajaxLink = new AjaxLink<Void>(ID_SCALAR_IF_REGULAR_CLEAR) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
setEnabled(false);
ScalarModel model = PageablePanelAbstract.this.getModel();
model.setObject(null);
target.add(formComponent);
// target.add(fileNameLabel);
}
};
ajaxLink.setOutputMarkupId(true);
formComponent.addOrReplace(ajaxLink);
final T txt = getTextFromModel();
formComponent.get(ID_SCALAR_IF_REGULAR_CLEAR).setVisible(txt != null && visibility == InputFieldVisibility.VISIBLE);
}
private T getTextFromModel() {
return getText(getModel());
}
protected enum InputFieldVisibility {
VISIBLE, NOT_VISIBLE
}
protected TextField<T> createTextField(final String componentId) {
return new TextField<>(componentId, newTextFieldValueModel());
// return (TextField) textField;
}
protected TextFieldValueModel<T> newTextFieldValueModel() {
return new TextFieldValueModel<>(this);
}
protected abstract IModel<String> getScalarPanelType();
}
关于我可以操纵哪些方法来获取两个文本字段的值的任何想法?谢谢。