XPages Request Processing Lifecycle -where does the package go - xpages

I am trying to run the code in the XPages Request Processing Lifecycle.
The 3rd bit of code says
But I don't know how to put in a package that matches the defined structure....
Code 3: XSPPhaseListener java class (put in a package that matches defined structure)
package com.ibm.xsp.util;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
/**
* #author Tony McGuckin, IBM
*/
public class XSPPhaseListener implements javax.faces.event.PhaseListener {
private static final long serialVersionUID = 1L;
public PhaseId getPhaseId() {
return PhaseId.ANY_PHASE;
}
public void beforePhase(PhaseEvent event) {
if(event.getPhaseId().equals(PhaseId.RESTORE_VIEW)){
System.out.println(" ");
System.out.println("Request:\tStarted...");
}
System.out.println(" ");
System.out.println("Lifecycle:\tBefore Phase: " + event.getPhaseId());
}
public void afterPhase(PhaseEvent event) {
System.out.println("Lifecycle:\tAfter Phase: " + event.getPhaseId());
System.out.println(" ");
if(event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)){
System.out.println("Request:\tCompleted.");
System.out.println(" ");
}
}
}

I think that's just a peculiar way of talking about the Java package - it's probably best to create a class in your own package ("com.company") instead of IBM's namespace. It wouldn't hurt anything to copy the package name he has there, but it's good practice. Then just make sure that you use that new full class name ("com.company.XSPPhaseListener") when you go to add it to the Faces Config.

Related

CDI Injected Bean from super class has null fields in child

I'm pretty new to the general procedure of bean injection. I've googled a lot but haven't found a solution to my problem.
Additional Information
Running Wildfly 9.0.1 final
EJB Vers. : 3.1
CDI Vers. : 2.2.16 (SP1)
JSF Vers. : 2.2
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.inject.Named;
#Named
#ViewScoped
public class UserEmailSettingsBean extends UserModuleSettingsBean {
private List<String> store;
private List<String> selectedStore;
//getters and setters, some fancy stuff...
#Override
public boolean saveProperties() {
LOG.info("Save called");
LOG.info(selectedStore.toString());
LOG.info(store.toString());
for(String prop : store) {
getProperties().setProperty(prop, String.valueOf(false));
}
for(String selectedProp : selectedStore){
LOG.info("selected: " + selectedProp + ":" + getProperties().getProperty(selectedProp) + " -> true");
getProperties().setProperty(selectedProp, String.valueOf(true));
}
super.saveProperties();
return true;
}
}
2nd Class:
public abstract class UserModuleSettingsBean implements ModuleSettings {
private static final long serialVersionUID = 459417872482285085L;
protected abstract List<String> getPropertiesName();
#Inject
private SettingsRepository settingsRepository;
#Inject
private SettingsService settingsService;
private Properties properties = new Properties();
#Override
public boolean saveProperties() {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
settingsService.store(getProperties(), username);
return (true);
}
}
The problem is, that the settingsService is constructed, however its field "settingsRepository" is null in my child class.
On the call of my save method from UserEmailSettings, getProperties().setProperty() is called with the right values, however its never stored, as the settingsRepository is null. I believe that is due to a wrong Injection for some reason.
Let me know if I need to provide more information ☺
Here is the needed part of SettingsRepository:
#Stateless
#TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class SettingsService implements Serializable {
private static final long serialVersionUID = 1695882717866085259L;
#Inject
SettingsRepository settingsRepository;
//...
}
And here the information SettingsRepository
#Stateless
public class SettingsRepository extends AbstractBaseRepository<Settings, Long> {
/**
* Instantiates a new settings repository.
*/
public SettingsRepository() {
super(Settings.class);
}
}
wanted to say my problem was that I didn't called an init() function on the settingsService to create the propertys, so getProperties was empty

Facing issues while navigating between the reports in Serenity

I am able to run the serenity test cases by using gradle. I use the command $ gradle clean test aggregate. Reports are also getting generated however when I click on the links provided in the Reports it fails to navigate and gives an error message. I have created the package structure as mentioned in the link below.
http://thucydides.info/docs/articles/an-introduction-to-serenity-bdd-with-cucumber.html
However still I'm not able to resolve this. Below are my Runner, Step definition and repository class.
Runner Class:
#RunWith(CucumberWithSerenity.class)
#CucumberOptions(features = "src/test/resources/features/LoginFeatureSerenity.feature")
public class TestRunnerSerenity {
}
Step Definition class:
package org.gradle.stepdef;
public class LoginStepDefSerenity {
#Managed
public WebDriver driver;
#ManagedPages
public Pages pages;
LoginPageRepository page;
// Scenario 1: Verify New Serenity Test Case
#Step
#Given("^User is on LoginSerenity Page$")
public void user_is_on_LoginSerenity_Page() throws Throwable {
page.open();
}
#Step
#When("^User enters valid Serenity credentials$")
public void user_enters_valid_Serenity_credentials() throws Throwable {
page.setusername("kaustubhsaxena");
page.setpassword("saxenasdhfghjfg");
page.loginButton.click();
}
#Step
#Then("^User is able to login Serenity$")
public void user_is_able_to_login_Serenity() throws Throwable {
assertThat(page.loginValidationMessage.getText(), is("Login failed"));
// page.logoutButon.click();
driver.close();
}
}
Repository Class
#DefaultUrl("http://localhost:8000/app/#/login")
public class LoginPageRepository extends PageObject {
#FindBy(id = "username")
protected WebElement username;
public void setusername(String value) {
element(username).type(value);
}
public WebElementFacade username() {
return element(username);
}
// Fields for Password
#FindBy(id = "password")
protected WebElement password;
public void setpassword(String value) {
element(password).type(value);
}
public WebElementFacade password() {
return element(password);
}
}
Can you please help me on this. Thanks in advance
Fortunately I got the solution of this.
In the build.gradle below plugin needs to be added so that it will handle the reporting part.
apply plugin: 'com.jfrog.bintray'
Thanks for your help on this.

Disable components in a large project

with a lot of developers and plenty of juniors I want to disable certain components such as <p:spacer> to prohibit using components for html/css issues. I want to limit the available components for libraries like omnifaces / primefaces / richfaces to a whitelist / blacklist thing basically.
Would this be a reasonable feature request for a library like omnifaces or is it to hard to build / to localized?
Basically, you can achieve this by providing a custom Application implementation (based on ApplicationWrapper) wherein you override the desired createComponent() method and throw e.g. IllegalArgumentException when a blacklisted component type and/or renderer type is passed.
Here's a kickoff example:
public class YourApplication extends ApplicationWrapper {
private static final Set<String> BLACKLISTED_COMPONENT_TYPES = unmodifiableSet(new HashSet<>(asList(
"org.primefaces.component.Spacer",
"com.example.SomeComponentType",
"com.example.OtherComponentType"
// Etc..
)));
private final Application wrapped;
public YourApplication(Application wrapped) {
this.wrapped = wrapped;
}
#Override
public UIComponent createComponent(FacesContext context, String componentType, String rendererType) {
if (BLACKLISTED_COMPONENT_TYPES.contains(componentType)) {
throw new IllegalArgumentException("You are not allowed to use this component.");
}
return super.createComponent(context, componentType, rendererType);
}
#Override
public Application getWrapped() {
return wrapped;
}
}
You can get it to run with this factory:
public class YourApplicationFactory extends ApplicationFactory {
private final ApplicationFactory wrapped;
public YourApplicationFactory(ApplicationFactory wrapped) {
this.wrapped = wrapped;
}
#Override
public Application getApplication() {
return new YourApplication(wrapped.getApplication());
}
#Override
public void setApplication(Application application) {
wrapped.setApplication(application);
}
}
Which is registered in faces-config.xml as below:
<factory>
<application-factory>com.example.YourApplicationFactory</application-factory>
</factory>
You can use tag file feature of jsf. You will declare tag file for each component that you want to use. After that, your team will only use these tag file in your project.

Unit test with WicketTester and CDI-Unit works in Eclipse but fails during Maven build. What am I missing?

I am trying out using CDI-Unit to test my Wicket components, which are using CDI for dependency injection. Tests seems to work perfectly in Eclipse but fail during my Maven build and I cant seem to find any hints and what is wrong.
I have created a simple abstract WicketPanel
public abstract class MyPanel extends Panel{
private static final long serialVersionUID = 4132041261965905788L;
private final RepeatingView rw;
#Inject
transient ReflectiveComponentFactory factory;
public MyPanel(String id) {
super(id);
rw = new RepeatingView(OVERLAY_COMPONENT_GROUP_ID);
add(rw);
}
#Override
public <CT extends Component> CT addComponent(Class<CT> componentType) {
return addComponent(componentType, OVERLAY_COMPONENT_ID);
}
protected <CT extends Component> CT addComponent(Class<CT> componentType, String overlayComponentId) {
WebMarkupContainer collapsableGroup = new WebMarkupContainer(rw.newChildId());
rw.add(collapsableGroup);
CT component = factory.createComponent(componentType, overlayComponentId);
collapsableGroup.add(component);
return component;
}
}
And the injection factory:
#ApplicationScoped
public class ReflectiveComponentFactory implements Serializable{
private static final long serialVersionUID = -4587243549845349456L;
public <CT extends Component> CT createComponent(Class<CT> componentType, String componentId){
try {
Constructor<CT> constructor = componentType.getConstructor(String.class);
return constructor.newInstance(componentId);
} catch (ReflectiveOperationException | SecurityException | IllegalArgumentException e) {
throw new ComponentCreationException(e);
}
}
}
And then created a unit test using CDI-Unit:
#RunWith(CdiRunner.class)
#AdditionalClasses(value={ReflectiveComponentFactory.class})
public class MyPanelTest {
private WicketTester tester;
#Inject
private BeanManager beanManager;
#Before
public void setup() {
tester = new WicketTester();
new CdiConfiguration(beanManager).setPropagation(ConversationPropagation.NONE).configure(tester.getApplication());
}
#Test
public void testAddComponentWithClass() {
MyPanelTested myPanel = new MyPanelTested("someId");
TestPanel panel1 = myPanel.addComponent(TestPanel.class);
TestPanel panel2 = myPanel.addComponent(TestPanel.class);
tester.startComponentInPage(myPanel);
tester.assertComponent(panel1.getPageRelativePath(), TestPanel.class);
tester.assertComponent(panel2.getPageRelativePath(), TestPanel.class);
tester.assertComponent(panel1.getPageRelativePath() + ":text", Label.class);
tester.assertComponent(panel2.getPageRelativePath() + ":text", Label.class);
}
}
#SuppressWarnings("serial")
class MyPanelTested extends MyPanel {
public MyPanelTested(String id) {
super(id);
}
}
I have not included TestPanel, but it is extremely simple (and more or less empty).
When I executed this in Eclipse, the test passes with green!
When I execute this with Maven I get the following:
org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.Dependent
at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:578)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:608)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:674)
at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:136)
at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:763)
at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:772)
at org.jboss.weld.manager.SimpleInjectionTarget$1.proceed(SimpleInjectionTarget.java:106)
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
at org.jboss.weld.manager.SimpleInjectionTarget.inject(SimpleInjectionTarget.java:102)
at org.apache.wicket.cdi.NonContextual.postConstruct(NonContextual.java:129)
at org.apache.wicket.cdi.NonContextualManager.postConstruct(NonContextualManager.java:65)
at org.apache.wicket.cdi.DetachEventEmitter.<init>(DetachEventEmitter.java:55)
at org.apache.wicket.cdi.CdiConfiguration.configure(CdiConfiguration.java:196)
.....
Any clues to what I am doing wrong?
The problem was caused by a bug in cdi-unit version 2.0.8. Bryn solved the problem (see https://github.com/BrynCooke/cdi-unit/issues/21) and it should therefore not appear if using cdi-unit 2.0.9 or greater.

How to transfer an array list of objects over the wire through GWTP action

I am trying to create an action in which the server needs to response an array list of objects over the wire to the client through GWTP Action.
Category class
package com.business.share;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
public class Category implements Serializable{
Long id;
protected String name;
protected String description;
protected boolean status;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean getStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
}
GetCategories class
package com.business.client.action;
import java.util.ArrayList;
import com.gwtplatform.dispatch.shared.ActionImpl;
import com.business.client.action.GetCategoriesResult;
import com.business.share.Category;
public class GetCategories extends ActionImpl<GetCategoriesResult> {
private ArrayList<Category> categories;
#SuppressWarnings("unused")
public GetCategories() {
// For serialization only
}
public GetCategories(ArrayList<Category> categories) {
this.categories = categories;
}
public ArrayList<Category> getCategories() {
return categories;
}
}
GetCategoriesResult class
package com.business.client.action;
import java.util.ArrayList;
import com.gwtplatform.dispatch.shared.Result;
import com.business.share.Category;
public class GetCategoriesResult implements Result {
private ArrayList<Category> categories;
#SuppressWarnings("unused")
private GetCategoriesResult() {
// For serialization only
}
public GetCategoriesResult(ArrayList<Category> categories) {
this.categories = categories;
}
public ArrayList<Category> getCategories() {
return categories;
}
}
GetCategoriesActionHandler class
package com.business.server.handler;
import java.util.ArrayList;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.business.client.action.GetCategories;
import com.business.client.action.GetCategoriesResult;
import com.business.share.Category;
import com.google.inject.Inject;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.shared.ActionException;
public class GetCategoriesActionHandler implements
ActionHandler<GetCategories, GetCategoriesResult> {
#Inject
public GetCategoriesActionHandler() {
}
#Override
public GetCategoriesResult execute(GetCategories action,
ExecutionContext context) throws ActionException {
ArrayList<Category> categories = new ArrayList<Category>();
// dummy data
Category cat1 = new Category();
cat1.setName("cat1");
cat1.setDescription("cat1 desc");
cat1.setStatus(true);
Category cat2 = new Category();
cat1.setName("cat2");
cat1.setDescription("cat2 desc");
cat1.setStatus(false);
categories.add(cat1);
categories.add(cat2);
return new GetCategoriesResult(categories);
}
#Override
public void undo(GetCategories action, GetCategoriesResult result,
ExecutionContext context) throws ActionException {
}
#Override
public Class<GetCategories> getActionType() {
return GetCategories.class;
}
}
And this is a piece of code in CategoryPresenter, which sends async to server.
#Override
protected void onReset() {
super.onReset();
GetCategories getCategoriesAction = new GetCategories();
dispatchAsync.execute(getCategoriesAction, getCategoriesCallback);
}
private final AsyncCallback<GetCategoriesResult> getCategoriesCallback =
new AsyncCallback<GetCategoriesResult>() {
#Override
public void onFailure(Throwable caught) {
}
#Override
public void onSuccess(GetCategoriesResult result) {
getView().getCategoryListBox().clear();
ArrayList<Category> categories = result.getCategories();
for(Category category : categories) {
getView().getCategoryListBox().addItem(category.getName());
}
}
};
I don't know what wrong with this piece of code, but GWT compiler always gives error like this.
Compiling module com.business.Business
Validating newly compiled units
Ignored 3 units with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
Finding entry point classes
[ERROR] Errors in 'file:/.blah..blah..blah../businessapp/src/com/business/client/presenter/CategoryPresenter.java'
[ERROR] Line 75: No source code is available for type com.business.share.Category; did you forget to inherit a required module?
[ERROR] Errors in 'file:/.blah..blah..blah../businessapp/src/com/business/client/action/GetCategoriesResult.java'
[ERROR] Line 11: No source code is available for type com.business.share.Category; did you forget to inherit a required module?
[ERROR] Unable to find type 'com.business.client.Business'
[ERROR] Hint: Previous compiler errors may have made this type unavailable
[ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
Following this error message, it means, com.business.share.Category is not found, but this file is physically stored in that package already. I don't understand why GWT could not find it. I noticed anywhere that I make call Category class, it brings this error always.
Somebody's got an idea on what's going on?
[EDIT]
The problem is solved.
In my Business.gwt.xml, I have
<source path='shared'/>
But my share package is com.business.share (without d)
I just rename the package name from share to shared.
Try to add an empty constructor to the Category class.

Resources