Portlet IPC after received Event

176 views Asked by At

I have a Navigation portlet which schows all Students, when a Student gets clicked im sending a event with the id of the clicked student to other portlets. Sending and receiving the event is not the problem, that works fine. What I don't get, is how to proceed with the id of the Object.

How do I update the portlets receiving the event to show the data of the Object they received. Since i only get the id, the first stept is to search in the DB and get alle data, afterwards update the portlets view.

Here my EventHandler:

The hskaId is the id of the Object wchich i need.

    public class ReceivedFeedbackEventHandler implements BridgeEventHandler{

    @Override
    public EventNavigationResult handleEvent(FacesContext facesContext, Event event) {
         EventNavigationResult eventNavigationResult = null;
         String eventQName = event.getQName().toString();

         if (eventQName.equals("{http://liferay.com/events}ipc.studentSelected")) {
             System.out.print("EVENT RECIVED STUDENT");

             String hskaId = (String) event.getValue();

         }

         if(eventQName.equals("{http://liferay.com/events}ipc.projectSelected")) {
             System.out.print("EVENT RECIVED PROJECT");
         }

         return eventNavigationResult;
    }
}

In the ManagedBean of the Portlet, im calling this to get all Students of a hskaId. Where "hskaId" stands right now, should the recieved event value go.

Student student = StudentLocalServiceUtil.findByProjectId("hskaId");

How do i get the received value of the event to the ManagedBean and update the view?

This is a crosspost: Link

1

There are 1 answers

1
stiemannkj1 On BEST ANSWER

You need to programmatically get your ManagedBean via the ELContext.

Here's how you should do it:

String elExpression = "#{studentsModelBean}";
ELContext elContext = facesContext.getELContext();
ValueExpression valueExpression = facesContext.getApplication().getExpressionFactory().createValueExpression(elContext, elExpression, StudentsModelBean.class);
StudentsModelBean studentsModelBean = (StudentsModelBean) valueExpression.getValue(elContext);
String hskaId = (String) event.getValue();
studentsModelBean.setStudent(hskaId);

String fromAction = null;
String outcome = "ipc.studentSelected";
eventNavigationResult = new EventNavigationResult(fromAction, outcome);

There is a working example of this which is done in the Liferay Faces Customers and Bookings portlet demo.